home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / src / sdpro.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  7KB  |  353 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: sdpro.c,v 1.5 1997/06/27 17:32:55 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /*
  34.  *    sdpro.c
  35.  *
  36.  *    Pvmd entry points for messages from scheduler.
  37.  *
  38. $Log: sdpro.c,v $
  39.  * Revision 1.5  1997/06/27  17:32:55  pvmsrc
  40.  * Updated for WIN32 header files & Authors.
  41.  *
  42.  * Revision 1.4  1997/01/28  19:27:31  pvmsrc
  43.  * New Copyright Notice & Authors.
  44.  *
  45.  * Revision 1.3  1996/10/25  13:58:06  pvmsrc
  46.  * Replaced old #includes for protocol headers:
  47.  *     - <pvmsdpro.h>, "ddpro.h", "tdpro.h"
  48.  * With #include of new combined header:
  49.  *     - <pvmproto.h>
  50.  *
  51.  * Revision 1.2  1996/10/24  21:04:53  pvmsrc
  52.  * Moved #include of "global.h" down below other headers:
  53.  *     - need to have all of the structures / types declared before
  54.  *         the globals can be declared...
  55.  *
  56.  * Revision 1.1  1996/09/23  23:44:42  pvmsrc
  57.  * Initial revision
  58.  *
  59.  * Revision 1.4  1995/07/19  21:28:16  manchek
  60.  * use new function pvmnametag instead of [dts]mname
  61.  *
  62.  * Revision 1.3  1994/10/15  19:29:02  manchek
  63.  * cast message tags for comparison as integers
  64.  *
  65.  * Revision 1.2  1994/07/18  19:22:56  manchek
  66.  * ALPHA segfaulted on array subscript
  67.  *
  68.  * Revision 1.1  1994/06/03  20:38:27  manchek
  69.  * Initial revision
  70.  *
  71.  *
  72.  */
  73.  
  74.  
  75. #ifdef NEEDMENDIAN
  76. #include <machine/endian.h>
  77. #endif
  78. #ifdef NEEDENDIAN
  79. #include <endian.h>
  80. #endif
  81. #ifdef NEEDSENDIAN
  82. #include <sys/endian.h>
  83. #endif
  84. #ifndef WIN32
  85. #include <rpc/types.h>
  86. #include <rpc/xdr.h>
  87. #include <sys/socket.h>
  88. #include <netinet/in.h>
  89. #include <sys/time.h>
  90. #else
  91. #include "pvmwin.h"
  92. #include <time.h>
  93. #include "..\xdr\types.h"
  94. #include "..\xdr\xdr.h"
  95. #endif
  96.  
  97. #include <sys/types.h>
  98. #include <stdio.h>
  99.  
  100. #include <pvm3.h>
  101. #include <pvmproto.h>
  102. #include "pvmalloc.h"
  103. #include "host.h"
  104. #include "pmsg.h"
  105. #include "waitc.h"
  106. #include "task.h"
  107. #include "bfunc.h"
  108. #include "global.h"
  109.  
  110.  
  111. extern int pvmdebmask;                /* from pvmd.c */
  112. extern int hostertid;                /* from pvmd.c */
  113. extern int hosterwid;                /* from ddpro.c */
  114. extern int pvmschedtid;                /* from pvmd.c */
  115. extern int taskertid;                /* from pvmd.c */
  116.  
  117.  
  118. /***************
  119.  **  Private  **
  120.  **           **
  121.  ***************/
  122.  
  123. int sm_bogus();
  124. int sm_exec();
  125. int sm_add();
  126. int sm_handoff();
  127. int sm_sthostack();
  128. int sm_taskx();
  129.  
  130. int (*smswitch[])() = {
  131.     sm_bogus,
  132.     sm_exec,
  133.     sm_bogus,
  134.     sm_bogus,
  135.     sm_bogus,
  136.     sm_bogus,
  137.     sm_bogus,
  138.     sm_add,
  139.     sm_bogus,
  140.     sm_bogus,
  141.     sm_taskx,
  142.     sm_bogus,
  143.     sm_handoff,
  144.     sm_bogus,
  145.     sm_bogus,
  146.     sm_sthostack,
  147.     sm_bogus,
  148. };
  149.  
  150.  
  151. int
  152. schentry(mp)
  153.     struct pmsg *mp;
  154. {
  155.     int c = mp->m_tag;
  156.  
  157.     if (pvmdebmask & PDMMESSAGE) {
  158.         pvmlogprintf("schentry() from t%x tag %s\n", mp->m_src,
  159.                 pvmnametag(c, (int *)0));
  160.     }
  161.  
  162.     if (c < (int)SM_FIRST || c > (int)SM_LAST) {
  163.         pvmlogprintf("schentry() message from t%x with bogus tag %d\n",
  164.                 mp->m_src, c);
  165.         goto bail;
  166.     }
  167.  
  168.     c -= SM_FIRST;
  169.     (smswitch[c])(mp);
  170.  
  171. bail:
  172.     pmsg_unref(mp);
  173.     return 0;
  174. }
  175.  
  176.  
  177. int
  178. sm_bogus(mp)
  179.     struct pmsg *mp;
  180. {
  181.     pvmlogprintf("sm_bogus() message from t%x tag %s ?\n",
  182.             mp->m_src, pvmnametag(mp->m_tag, (int *)0));
  183.     return 0;
  184. }
  185.  
  186.  
  187. /*    sm_exec(wid)
  188. *
  189. *    Request the pvmd to start task processes.
  190. *    Just like DM_EXEC but different.
  191. */
  192.  
  193. int
  194. sm_exec(mp)
  195.     struct pmsg *mp;
  196. {
  197.     struct pmsg *rmp;
  198.  
  199.     rmp = mesg_new(0);
  200.     rmp->m_dst = mp->m_src;
  201.     rmp->m_ctx = mp->m_ctx;
  202.     rmp->m_tag = SM_EXECACK;
  203.     rmp->m_wid = mp->m_wid;
  204.     exectasks(mp, rmp, mp->m_src);
  205.     return 0;
  206. }
  207.  
  208.  
  209. /*    sm_add()
  210. *
  211. *    Scheduler requests the master pvmd to add hosts.
  212. *    Just like DM_ADD but different.
  213. *
  214. *    SM_ADD(wid) {
  215. *        int count
  216. *        string name[count]
  217. *    }
  218. */
  219.  
  220. int
  221. sm_add(mp)
  222.     struct pmsg *mp;
  223. {
  224.     struct pmsg *rmp;
  225.  
  226.     rmp = mesg_new(0);
  227.     rmp->m_dst = mp->m_src;
  228.     rmp->m_ctx = mp->m_ctx;
  229.     rmp->m_tag = SM_ADDACK;
  230.     rmp->m_wid = mp->m_wid;
  231.     addhosts(mp, rmp);
  232.     return 0;
  233. }
  234.  
  235.  
  236. /*    sm_taskx()
  237. *
  238. *    Tasker notifies us that process exited.
  239. *
  240. *    SM_TASKX() {
  241. *        int tid        // of toasted process
  242. *        int status    // exit status
  243. *        int u_sec    // user time used
  244. *        int u_usec
  245. *        int s_sec    // system time used
  246. *        int s_usec
  247. *    }
  248. */
  249.  
  250. int
  251. sm_taskx(mp)
  252.     struct pmsg *mp;
  253. {
  254.     int tid;
  255.     struct task *tp;
  256.     int i;
  257.  
  258.     if (mp->m_src != taskertid) {
  259.         pvmlogprintf("sm_taskx() from t%x (not the tasker)\n", mp->m_src);
  260.         return 0;
  261.     }
  262.     upkuint(mp, &tid);
  263.     if (tp = task_find(tid)) {
  264.         if (pvmdebmask & PDMTASK) {
  265.             pvmlogprintf("sm_taskx() t%x\n", tid);
  266.         }
  267.         upkuint(mp, &tp->t_status);
  268.         upkuint(mp, &i);
  269.         tp->t_utime.tv_sec = i;
  270.         upkuint(mp, &i);
  271.         tp->t_utime.tv_usec = i;
  272.         upkuint(mp, &i);
  273.         tp->t_stime.tv_sec = i;
  274.         upkuint(mp, &i);
  275.         tp->t_stime.tv_usec = i;
  276.         task_cleanup(tp);
  277.         task_free(tp);
  278.  
  279.     } else {
  280.         if (pvmdebmask & PDMTASK) {
  281.             pvmlogprintf("sm_taskx() t%x (no such)\n", tid);
  282.         }
  283.     }
  284.     return 0;
  285. }
  286.  
  287.  
  288. /*    sm_handoff()
  289. *
  290. *    Current scheduler for this pvmd gets reassigned.
  291. *
  292. *    SM_HANDOFF() {
  293. *        uint newsched        // tid
  294. *    }
  295. */
  296.  
  297. int
  298. sm_handoff(mp)
  299.     struct pmsg *mp;
  300. {
  301.     int tid;
  302.  
  303.     upkuint(mp, &tid);
  304.     if (pvmdebmask & PDMSCHED) {
  305.         pvmlogprintf("sm_handoff() old t%x new t%x\n", pvmschedtid, tid);
  306.     }
  307.     pvmschedtid = tid;
  308.     return 0;
  309. }
  310.  
  311.  
  312. /*    sm_sthostack()
  313. *
  314. *    Hoster finishes starting slave pvmds.
  315. *
  316. *    SM_STHOSTACK(wid_rtn) {
  317. *        {
  318. *            int tid
  319. *            string result
  320. *        } []                // implied
  321. *    }
  322. */
  323.  
  324. int
  325. sm_sthostack(mp)
  326.     struct pmsg *mp;
  327. {
  328.     struct waitc *wp;        /* wait context on pvmd' */
  329.  
  330.     if (mp->m_src != hostertid) {
  331.         pvmlogprintf("sm_sthostack() from t%x (not the hoster)\n",
  332.                 mp->m_src);
  333.         return 0;
  334.     }
  335.  
  336.     if (mp->m_wid != hosterwid) {
  337.         pvmlogprintf("sm_sthostack() from t%x bad wid %d wanted %d\n",
  338.                 mp->m_src, mp->m_wid, hosterwid);
  339.         return 0;
  340.     }
  341.  
  342.     if (!(wp = wait_find(hosterwid)))
  343.         return 0;
  344.  
  345.     hosterwid = 0;
  346.  
  347.     startack(wp, mp);
  348.  
  349.     return 0;
  350. }
  351.  
  352.  
  353.